/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.dal;

import entity.Administrator;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Hailk_c00639
 */
public class AdministratorDAL {

    MyConnection con = new MyConnection();

    public List<Administrator> getAllAdministrator() {
        List<Administrator> lst = new ArrayList<>();

        try {
            CallableStatement call = con.getConnection().prepareCall("{call sp_GetAllAdministrator}");
            ResultSet rs = call.executeQuery();

            while (rs.next()) {
                Administrator admin = new Administrator();
                admin.setAdminID(rs.getInt("AdminID"));
                admin.setFullName(rs.getString("FullName"));
                admin.setAdminName(rs.getString("AdminName"));
                admin.setPassword(rs.getString("[Password]"));
                admin.setEmail(rs.getString("Email"));
                admin.setRoleID(rs.getInt("RoleID"));

                lst.add(admin);
            }

        } catch (SQLException ex) {
            Logger.getLogger(AdministratorDAL.class.getName()).log(Level.SEVERE, null, ex);
        }
        finally
        {
            con.closeDB();
        }
        return lst;
    }
}
